import 'package:flutter/material.dart';
import 'package:uuid/uuid.dart';
import '../models/todo.dart';

class TodoProvider extends ChangeNotifier {
  final List<Todo> _todos = [];
  final _uuid = const Uuid();

  List<Todo> get todos => _todos;

  void addTodo(String title) {
    if (title.isEmpty) return;
    
    _todos.add(Todo(
      id: _uuid.v4(),
      title: title,
    ));
    notifyListeners();
  }

  void toggleTodo(String id) {
    final todo = _todos.firstWhere((todo) => todo.id == id);
    todo.isCompleted = !todo.isCompleted;
    notifyListeners();
  }

  void deleteTodo(String id) {
    _todos.removeWhere((todo) => todo.id == id);
    notifyListeners();
  }

  int get completedCount => _todos.where((todo) => todo.isCompleted).length;
  
  int get remainingCount => _todos.where((todo) => !todo.isCompleted).length;
} 